package com.tgr.component.ui.calendar
{
	public class CustomizerForWeeklyCalendar 
	implements ScheduleCanvasCustomizer
	{
		private var areDraggedItemsAcceptableFunction:Function;
		
		private var entryLabelFunction:Function;
		
		
		public function CustomizerForWeeklyCalendar(fAreDraggedItemsAcceptable:Function=null
													,entryLabelFunction:Function=null)
		{
			areDraggedItemsAcceptableFunction = fAreDraggedItemsAcceptable;
			this.entryLabelFunction = entryLabelFunction;
		}

		public function avoidOverLap():Boolean
		{
			return true;
		}
		
		private function getTimeLabel(hours:Number, minutes:Number):String
		{
			var lbl:String = null;
			
			switch(hours)
			{
				case 0:
					lbl = "12:"+(minutes<10
						?("0"+minutes+"am")
						:(minutes+"am"));
						break;
				default: 
					if(hours<10)
					{
						lbl = "0" + hours +":" +
						((minutes<10)
						?("0"+minutes+"am")
						:(minutes+"am"));
							
					}
					else if(hours>=10 && hours<12)
					{
						lbl = hours +":" +
						((minutes<10)
						?("0"+minutes+"am")
						:(minutes+"am"));						
					}
					else
					{
						lbl = hours +":" +
						((minutes<10)
						?("0"+minutes+"pm")
						:(minutes+"pm"));						
					}				
			}
			
			return lbl;
		}
		
		private function getDayLabel(n:Number):String
		{
			var lbl:String = "";
			switch(n)
			{
				case 0: lbl = "Sun";break;
				case 1: lbl = "Mon";break;
				case 2: lbl = "Tue"; break;
				case 3: lbl = "Wed"; break;
				case 4: lbl = "Thu"; break;
				case 5: lbl = "Fri"; break
				case 6: lbl = "Sat"; break;
			}
			return lbl;
		}
		
		public function getEntryTopLabel(entry:BasicScheduleCanvasEntry):String
		{

			var interpretEntry:EntryForWeeklyCalendar = new EntryForWeeklyCalendar(entry);
			
			return getTimeLabel(interpretEntry.startHours,interpretEntry.startMinutes);
			
		}
		
		public function getEntryBottomLabel(entry:BasicScheduleCanvasEntry):String
		{
			var interpretEntry:EntryForWeeklyCalendar = new EntryForWeeklyCalendar(entry);
			
			return getTimeLabel(interpretEntry.endHours,interpretEntry.endMinutes);			
		}
		
		public function getEntryLeftLabel(entry:BasicScheduleCanvasEntry):String
		{
			var interpretEntry:EntryForWeeklyCalendar = new EntryForWeeklyCalendar(entry);
				
			return getDayLabel(interpretEntry.getDayOfWeek());			
		}
		
		public function getEntryRightLabel(entry:BasicScheduleCanvasEntry):String
		{			
			return "";			
		}
		
		public function getEntryLabel(entry:BasicScheduleCanvasEntry):String
		{
			return entryLabelFunction==null?"":entryLabelFunction(entry);
		}
		
		public function getRowLabel(n:Number):String
		{
			var label:String = "";
			
			switch(n)
			{
				case 0: label="12:00am"; break;
				case 12: label="12:00pm";break;
				default: 
					{
						label=(n<12)?n+":00am":(n%12)+":00pm";
					}break;
			}
			
			return label;
		}
		
		public function getColumnLabel(n:Number):String
		{
			return getDayLabel(n);
		}
		
		public function getNumRows():Number
		{
			return 24;
		}
		
		public function getNumColumns():Number
		{
			return 7;
		}
		
		public function areDraggedItemsAcceptable(items:Array):Boolean
		{
			if(areDraggedItemsAcceptableFunction==null)
			{
				return true;
			}
			
			return areDraggedItemsAcceptableFunction(items);
		}
		
		public function dontMoveDirection():int
		{
			return -1;//default
		}
		
		public function dontResizeDirection():int
		{
			return ScheduleCanvas.SCHEDULEENTRY_DIRECTION_LEFTRIGHT;
		}
		
		public function guideToLeftEdge():Boolean
		{
			return true;
		}
		
		public function guideToTopEdge():Boolean
		{
			return false;
		}
		
		public function get_rearrange_avoid_y_overlap():Boolean
		{
			return false;
		}
		
	}
}